********************************************************************************************************************
*****Do-file for Tables A19
*****Who is mobilized to vote by short text messages? Evidence from a nationwide field experiment with young voters
********************************************************************************************************************
*****Last edited 24/6/5
********************************************************************************************************************
*****Ado packages needed: estout
********************************************************************************************************************


clear all


*Use data
use \data\dataforanalysis230522_v2.dta, clear
*Set basecategory
fvset base 8 moses1d
label variable treated "Treated"



*************************************************
*****Table A19
*************************************************

*Generate dummies for mother's income group
sum molincome if voted22!=.  & treated!=. & female!=., detail
gen lowincome=molincome<r(p50) & molincome!=.
gen highincome=molincome>=r(p50) & molincome!=.


*Generate dummies for mother's profession group
replace ammattikoodi_k="." if ammattikoodi_k=="XXX"
gen prof1d=real(substr(ammattikoodi_k,1,1)) 

gen mmprof1d=prof1d if age==mage & female==1
bys petu: egen mprof1d=mean(mmprof1d)
replace mprof1d=. if a25lkm==0 | a25lkm==. | diffage<16 | age>25

gen moprof1d=mprof1d
replace moprof1d=prof1d if moprof1d==.


gen lowskill=.
replace lowskill=1 if moprof1d>3 & moprof1d!=.
replace lowskill=1 if moprof1d==0
gen highskill=.
replace  highskill=1 if moprof1d<4 & moprof1d>0



eststo clear
eststo M1: reg voted22 treated molincome female age foreign i.moses1d firstvote i.mohighschool if lowincome==1, cluster(kunta19)
estadd local Controls "Yes"
mean voted22 if e(sample)==1 & treated==0
estadd scalar umean=r(table)[1,1]: M1
eststo M2: reg voted22 treated molincome female age foreign i.moses1d firstvote i.mohighschool if highincome==1, cluster(kunta19)
estadd local Controls "Yes"
mean voted22 if e(sample)==1 & treated==0
estadd scalar umean=r(table)[1,1]: M2
eststo M3:  reg voted22 treated molincome female age foreign i.moses1d firstvote i.mohighschool if lowskill==1, cluster(kunta19)
estadd local Controls "Yes"
mean voted22 if e(sample)==1 & treated==0
estadd scalar umean=r(table)[1,1]: M3
eststo M4:  reg voted22 treated molincome female age foreign i.moses1d firstvote i.mohighschool if highskill==1, cluster(kunta19)
estadd local Controls "Yes"
mean voted22 if e(sample)==1 & treated==0
estadd scalar umean=r(table)[1,1]: M4
local header "& \multicolumn{4}{c}{Outcome: Voted} \\"
local numbers "& (1) & (2) & (3) & (4)\\ \hline"
local titles1 "& < Median Income & > Median Income  & Low Skilled Occupation & High Skilled Occupation"
local emptyrow "& & & &   \\ "
local line "& & & &  \hline \\ "

local dstars " "
local sestars " "
esttab, keep (treated) noobs label se b(%9.3f) se(%9.3f) star(* 0.10 ** 0.05 *** 0.01) ///
scalars("Controls Controls" "umean Untreated $\bar{Y}$" "N Observations") ///
sfmt(%9.3f %9.3f %9.0fc) mlabels(none) nonumbers posthead("`header'" "`emptyrow'" "`numbers'" "`emptyrow'") ///
refcat(treatedf "", nolabel below) title("Heterogeneity by Income and Profession Skill Level") nonotes replace